You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verdict: Request changes. The fix is correct, but it must be rebased, and as it stands it probably does not fix the scenario in #2005.
Correctness
The change makes SocketcanBus.send() follow the BusABC.send() contract: timeout=None now waits indefinitely for the socket to become writable, instead of polling once. I applied the production change to current main and checked:
send(msg) passes None to the poll call, including on retries after a partial write.
send(msg, timeout=0) and send(msg, timeout=0.2) behave as before.
The existing SocketCAN tests pass.
Requested changes
Rebase onto main.Replaced select.select() with select.epoll() in SocketcanBus #2056 replaced select.select() with select.epoll() in SocketcanBus. The production change still applies cleanly, but test/test_socketcan.py conflicts. The new test also patches select.select, which send() no longer calls, and on main it fails with AttributeError: 'SocketcanBus' object has no attribute '_epoll'. Please rewrite the test against the epoll-based implementation.
Do not close SocketcanBus.send() timeout semantics differ from BusABC.send() #2005 with this PR, or extend the fix. When the transmit queue of a SocketCAN interface is full, Linux usually returns ENOBUFS from send() rather than reporting the socket as not writable. This is the default case: CAN devices use txqueuelen 10, which fills well before the socket send buffer does. ENOBUFS goes through _send_once(), which still raises CanOperationError("Failed to transmit: No buffer space available") immediately, whatever the timeout. So the reproducer in SocketcanBus.send() timeout semantics differ from BusABC.send() #2005 most likely still fails with this change. Waiting only takes effect when the socket send buffer fills before the device queue. To fully fix SocketcanBus.send() timeout semantics differ from BusABC.send() #2005, send() would also need to retry on ENOBUFS until the timeout expires. This analysis is based on kernel behaviour and has not been reproduced on hardware.
Add a changelog fragment. For users who rely on the old behaviour, this is a visible change: send() without a timeout can now block instead of raising. This also affects ThreadSafeBus (a blocked send() holds the send lock, so shutdown() waits as well) and thread-based cyclic tasks, which call send() without a timeout. The fragment should state the new behaviour explicitly, for example:
``SocketcanBus.send()`` now waits indefinitely for the transmit queue when ``timeout`` is ``None``, as documented for ``BusABC.send()``, instead of raising immediately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2005.
SocketCAN now follows the BusABC timeout contract:
send(timeout=None)waits indefinitely for the transmit queue instead of polling immediately.Validation:
python -m pytest test/test_socketcan.py -qpython -m compileall can/interfaces/socketcan/socketcan.py